package com.shop.web.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.dbutils.QueryRunner;

import com.shop.domain.Order;
import com.shop.domain.Product;
import com.shop.service.OrderService;
import com.shop.utils.JDBCUtils;

/**
 * Servlet implementation class UpdateStateServlet
 */
@WebServlet("/UpdateStateServlet")
public class UpdateStateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateStateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String p2_Order = req.getParameter("p2_Order");
//		int num = Integer.parseInt(req.getParameter("num"));
		OrderService service = new OrderService();
		service.pay(p2_Order);
		//order.setId(p2_Order);
		

		
		req.getRequestDispatcher("/success.jsp").forward(req, resp);
//		public void updateState(String r6_Order) {
//			String sql = "update  orders set state = 1 where id = ?";
//			try {
//				QueryRunner queryRunner = new QueryRunner(JDBCUtils.getDataSource());
//				queryRunner.update(sql, r6_Order);
//			} catch (SQLException e) {
//				e.printStackTrace();
//			}
//		}
	}

}
